//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(type) {
		
	var obj = {
			"text" : '新建贷款债权赎回',
			"url" : contextRootPath + '/loanRedem/prepareExecute/toAdd'
		};

	parent.showObj(obj);
}


//修改 事件
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		jyDialog({"type":"info"}).alert("请选择待修改的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		jyDialog({"type":"info"}).alert("请选择一条数据！");
		return;
	}
	
	var contractCode = iframe.iframeObj["table"].getSelectedObjs("contractCode");
	var dealCode = iframe.iframeObj["table"].getSelectedObjs("dealCode");
	var cooperativeAgencyDealStatus = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus");
	var obj={"text":'修改贷款赎回交易',"url":contextRootPath+'/loanRedem/prepareExecute/toBackRedemptionUpdate?contractCode=' + contractCode + "&dealCode=" + dealCode + "&id=" + v_ids+ "&cooperativeAgencyDealStatus=" + cooperativeAgencyDealStatus};
	parent.showObj(obj);
}


//删除 事件
function deleteData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		jyDialog({"type":"info"}).alert("请选择待删除的数据！");
		return;
	}
	jyDialog({"type":"question"}).confirm("您确认要删除选择的数据吗？",function(){
		 $.ajax({
	            type:"POST",
	            dataType : "json",
	            url:contextRootPath+"/loanRedem/deleteDeal?ids="+v_ids,
	            success:function(msg){
	            	jyDialog({"type":"error"}).alert(msg.msg);
	            	var v_status = msg.status;
	            	//删除成功后
	            	if(v_status.indexOf('ok') >-1){
	            		iframe.iframeObj["table"].removeSelectedRow();
	            		queryData();
	            	}
	            	
	            	
	            }
	        });
	},"完成提示");
}
var deleteContractNos = "";
// 释放删除  债权明细释放 zhoupeng 20160706
function releaseData(obj, creditorStatus,creditCode, contractNo, backAmt){
	var isNew = $('#isNew').val(); 
	if (isNew == "true") {
		 //var contractNo = $(obj).parent().parent().parent().parent().find("td").eq(1).text();
		 deleteContractNos += contractNo + ",";
		 $(obj).parent().parent().parent().parent().remove();
	} else {
		jyDialog({"type":"question"}).confirm("您确认要删除选择的数据吗？",function(){
			var dealCode = $('#dealCode').val(); 
			 $.ajax({
		            type:"POST",
		            dataType : "json",
		            url:contextRootPath+"/loanRedem/releaseData?creditCode="+creditCode+ "&creditorStatus=" + creditorStatus+ "&dealCode=" + dealCode,
		            success:function(msg){
		            	jyDialog({"type":"error"}).alert(msg.msg);
		            	var v_status = msg.status;
		            	//删除成功后
		            	if(v_status.indexOf('ok') >-1){
		            		$(obj).parent().parent().parent().parent().remove();
		            		 //回显汇总值
		            		showSumValue(backAmt);
		            	}
		            }
	        });
		},"完成提示");
	}

}
//回显汇总金额、条数
function showSumValue(backAmt) {
	var num = $('#detialNumber').val();
	$('#detialNumber').val(num-1);
	var amt = $('#sumMakeCreditorValue').val();
	$('#sumMakeCreditorValue').val((amt-backAmt).toFixed(2));
}

//结算申请
function settleDeal(){
	var ids = iframe.iframeObj["table"].getSelectedObjs("dealCode").join(",");
	//如果没有选中 数据则
	if(ids == ""){
		jyDialog({"type":"info"}).alert("请选择待结算的数据！");
		return;
	}
	//如果选择多个 择提示
	if(ids.indexOf(",") > -1){
		jyDialog({"type":"info"}).alert("请选择一条数据！");
		return;
	}
	//贷款回购成功的数据可做结算申请
	var cooperativeAgencyDealStatus = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus");
	if(cooperativeAgencyDealStatus != "03"){
		jyDialog({"type":"info"}).alert("请选择贷款回购成功的数据做结算申请！");
		return;
	}
	
	jyDialog({"type":"question"}).confirm("您确认要结算选择的数据吗？",function(){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/loanRedem/settleDeal?ids="+ids,
            success:function(result){
            	var msg = result.msg;
            	if(msg.indexOf("\n\n") > -1){
            		var showMsg = "";
            		var aa = new Array();
            		aa = msg.split("\n\n"); //处理换行符,弹出框控件不识别
                	for(i=0 ; i<aa.length-1; i++){
                		showMsg += " ● " + aa[i] + "<br\><br\>";
                	}
                	jyDialog({"type":"error"}).alert(showMsg);
            	}else{
            		jyDialog({"type":"error"}).alert(msg);
            	}
            	var v_status = result.status;
            	if(v_status.indexOf('ok') >-1){
            		queryData();
            	}
            }
        });
    },"结算提示对话框");
}

//刷新结算状态
function refreshSettleStatus(){
	$.ajax({
		url: contextRootPath+"/creditDealController/realTimeUpdateSettleResult",
		type: 'post',
		dataType: 'json',
		success: function(msg) {
				jyDialog({"type":"info"}).alert(msg.msg);
				var v_status = msg.status;
		    	if(v_status.indexOf('ok') >-1){
		    		queryData();
		    	}
				
		}
	});
}